﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Report;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Model.ReportFilter;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Util;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// 获取工艺路线表单插件
/// </summary>
/// <remarks>
/// 功能：1、点击获取生产成本时，获取工艺路线，更新到但具体
/// 创建人：lxl
/// 创建日期：2024-8-26
/// 修改信息（1）：修改人，修改日期，修改内容
/// </remarks>
namespace LM.YF.K3Cloud.Plugin
{
    [HotUpdate, Description("获取工艺路线表单插件")]
    public class GetRouteBillPlugin : AbstractDynamicFormPlugIn
    {
        public override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //获取年份
            int fyear = DateTime.Now.Year;
            int fmonth = DateTime.Now.Month;
            this.Model.SetValue("F_QLTK_year", fyear);
            this.Model.SetValue("F_QLTK_month", fmonth);
        }

        public override void AfterButtonClick(AfterButtonClickEventArgs e)
        {
            base.AfterButtonClick(e);
            //点击获取数据后
            if (e.Key.ToUpper() == "F_QLTK_GETROUTE")
            {
                string strSql;
                //获取选取的年月
                string fyear = Convert.ToString(this.Model.GetValue("F_QLTK_year"));
                string fmonth = Convert.ToString(this.Model.GetValue("F_QLTK_month"));
                string forgid = Convert.ToString((this.Model.GetValue("F_QLTK_OrgId") as DynamicObject)?["id"]);
                if (string.IsNullOrEmpty(fyear) || string.IsNullOrEmpty(fmonth) || string.IsNullOrEmpty(forgid))
                {
                    this.View.ShowMessage("更新失败");
                    return;

                }
                strSql = $"exec dev_p_getRoute {fyear},{fmonth},{forgid}";
                int fresult = DBUtils.Execute(this.Context, strSql);
                if (fresult > 0)
                {
                    var result = new FormResult("sucess");
                    this.View.ReturnToParentWindow(result);
                    this.View.ShowMessage("更新成功");
                }
                else { this.View.ShowMessage("更新失败"); }
            }
        }


    }
}
